<?php
$regemp=$_POST['txtRegno'];
include'admin/logic/Classes/db.php';
$y=new DbConnect();
$conn=$y->getConnection();
$sql1="select * from login where emp_reg ='$regemp'";
$result1=mysql_query($sql1,$conn) or die(mysql_error());
$num1=mysql_num_rows($result1);
if($num1==1){
if(strlen($regemp)==4){
$sql="select * from employee where emp_no='$regemp'";
$result=mysql_query($sql,$conn) or die(mysql_error());
} else {
$sql="select * from student where reg_no='$regemp'";
$result=mysql_query($sql,$conn) or die(mysql_error());
		}
$num=mysql_num_rows($result);
if($num==1){
while($row=mysql_fetch_array($result)){
$email=$row['email'];
}
if(!($email=="")){
$password=rand(6,1000000);
$x=md5($password);

//mail server ip address
$Mailserver = "192.168.1.3";
//php ini set
ini_set("SMTP",$Mailserver);

$emails = "usheshy@gmail.com";
ini_set("sendmail_from",$emails);
$subject="New password";
$message="New Password -".$password;
mail($email, $subject, $message, "From;Admin of CNC MIS");
$sqls="update login set p_word='$x' where emp_reg='$regemp' "; 		
mysql_query($sqls,$conn) or die(mysql_error());
$msg="Successfully Sent the Password";
header("location:forgot.php?tab=$msg"); 
} else {
$msg="No Email Related To This Number";
header("location:forgot.php?tab=$msg"); 	
}
} else{
if(strlen($regemp)==4){
$msg="Invalid Employee Number";
header("location:forgot.php?tab=$msg"); 	
} else {
$msg="Invalid Registration Number";
header("location:forgot.php?tab=$msg"); 	
	 }
}
} else{
$msg="NO User Privileges To Access the System";
header("location:forgot.php?tab=$msg"); 	
}
?>